package com.yunkeji.api.common.controller;

import com.yunkeji.api.common.bo.VersionCheck;
import com.yunkeji.api.common.service.SysConfigService;
import com.yunkeji.api.common.vo.SysConfigVo;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.enums.app.AccountTypeEnums;
import com.yunkeji.config.annotation.ApiAuth;
import com.yunkeji.dao.domain.SysVersion;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通用配置获取
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/config")
public class ConfigController extends BaseController {
    private final SysConfigService sysConfigService;

    /** 获取通用配置 */
    @PostMapping(value = "/configList")
    @ApiAuth(allow = {AccountTypeEnums.客服, AccountTypeEnums.用户})
    public R<SysConfigVo> configList() {
        return R.ok(sysConfigService.configList());
    }

    /** 更新检测-返回空无更新,有值forceUpdate表示是否强制更新 */
    @PostMapping(value = "/updateCheck")
    @ApiAuth(allow = {AccountTypeEnums.客服, AccountTypeEnums.用户})
    public R<SysVersion> updateCheck(@RequestBody VersionCheck check) {
        return R.ok(sysConfigService.updateCheck(check));
    }
}
